{extend name="common/base"}
{block name="title"}首页{/block}
{block name="content"}
        <!-- 内容区域 -->
        <div class="tpl-content-wrapper">
            <div class="row-content am-cf">
                <div class="row">
                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                        <div class="widget am-cf">
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">新增商品子规格</div>
                                <div class="widget-function am-fr">
                                    <a href="javascript:;" class="am-icon-cog"></a>
                                </div>
                            </div>
                            <div class="widget-body am-fr"> 

                                <form class="am-form tpl-form-border-form tpl-form-border-br" action="{:Url('/admin/goods/insertGuigeSon')}" enctype="multipart/form-data" method="post">
                                    <div class="am-form-group">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">商品名称 </label>
                                        <div class="am-u-sm-9">
                                            <select name="goods_id" id="sel1" style="width:30%;">
                                                {volist name="goods_list" id="va"}
                                                <option value="{$va.id}" style="color:#888;">{$va.name}</option>
                                                {/volist}
                                            </select>
                                        </div>
                                    </div>
                                    <div class="am-form-group">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">商品规格名称 </label>
                                        <div class="am-u-sm-9">
                                            <select name="guigeType_id" id="sel2" style="width:30%;">
                                                <option value="null" style="color:#888;" selected>无</option>
                                                {volist name="goods_guige_list" id="va"}
                                                <option value="{$va.id}" style="color:#888;">{$va.name}</option>
                                                {/volist}
                                            </select>
                                        </div>
                                    </div>
                                    <div class="am-form-group">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">商品子规格名称 </label>
                                        <div class="am-u-sm-9">
                                            <input type="text" class="tpl-form-input" id="user-name" placeholder="例如:内存/颜色/尺寸" name="name">
                                        </div>
                                    </div>
                                    <div class="am-form-group" id="afterDiv">
                                        <label for="user-name" class="am-u-sm-3 am-form-label">商品规格属性名称 </label>
                                        <div class="am-u-sm-9">
                                            <input type="text" class="tpl-form-input" id="user-name" placeholder="例如:64G/白色/中码" name="guigeType_name[]" style="width:20%;float:left;margin-right:8px;">
                                            <input type="text" class="tpl-form-input" id="user-name" placeholder="例如:64G/白色/中码" name="guigeType_name[]" style="width:20%;float:left;margin-right:8px;">
                                            <input type="text" class="tpl-form-input" id="user-name" placeholder="例如:64G/白色/中码" name="guigeType_name[]" style="width:20%;float:left;margin-right:8px;">
                                            <input type="text" class="tpl-form-input" id="user-name" placeholder="例如:64G/白色/中码" name="guigeType_name[]" style="width:20%;float:left;margin-right:8px;">
                                        </div>
                                    </div>
                                    <div class="am-form-group">
                                        <div class="am-u-sm-9 am-u-sm-push-3">
                                            <button type="submit" class="am-btn am-btn-primary tpl-btn-bg-color-success ">确认提交</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
{/block}

{block name="footer-js"}
<script>
$("select#sel1").change(function(){
    getGuigeName($(this).val());
});
//获取商品规格选项
function getGuigeName(id){
    $.ajax({
        url:"{:Url('admin/Goods/get_guige')}",
        type:"get",
        data:{id:id},
        dataType:"json",//数据通信的类型            
        success:function(data){
            console.log(data);
            var length = data.length;
            if(length==0){  
                $("#sel2").empty();
                $("#sel2").append('<option value="null" style="color:#888;" selected>无</option>');
            }else{
                $("#sel2").empty();
                for(var i=0;i<length;i++){
                    $("#sel2").append('<option value="'+data[i].id+'" style="color:#888;">'+data[i].name+'</option>');
                }
            }            
        }
    });
}
</script>
{/block}